/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.adaptor.method.setentityvalue;

import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.coreGenerator.entityGenerator.CommonModelCoreGeneratorContext;
import com.inspur.edp.cef.generator.repository.dac.DataTypeDacGenContext;
import com.inspur.edp.cef.repository.dbcolumninfo.DbColumnInfoCollection;
import com.inspur.edp.das.commonmodel.IGspCommonObject;

import java.lang.reflect.Method;
import java.util.ArrayList;

public class EntitySetEntityValueGenerator extends SetEntityValueGenerator
{
	private String nodeCode;
	private boolean isChild;
	private IGspCommonObject gspCommonObject;
	public EntitySetEntityValueGenerator(DataTypeDacGenContext dacContext, IGspCommonDataType gspCommonDataType, String nodeCode, boolean isChild, java.util.HashMap<String, String> mappingPropNames, DbColumnInfoCollection dbColumns)
	{
		super(dacContext, gspCommonDataType, mappingPropNames, dbColumns);
		this.nodeCode = nodeCode;
		this.isChild = isChild;
	}

	@Override
	protected String buildEntityTypeName()
	{
		if (isChild)
		{
			java.util.HashMap<String, MediateType> childTypes = ((CommonModelCoreGeneratorContext) dacContext.getReposContext().getCefContext().getCefGenContext().getCoreGenContext()).getEntityDataMediateTypes();
			if (!childTypes.containsKey(nodeCode))
			{
				throw new RuntimeException("不存在编号为" + nodeCode + "的子表");
			}
			return childTypes.get(nodeCode).getClassName();
		}
		return ((CommonModelCoreGeneratorContext) dacContext.getReposContext().getCefContext().getCefGenContext().getCoreGenContext()).getEntityDataMediateTypes().get(nodeCode).getClassName();
	}
}
